package com.fit.spring.boot.mapper.autoconfigure;


import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;

import tk.mybatis.spring.mapper.MapperScannerConfigurer;

/**
 * 通用的mapper自动配置类
 * 当定义了MapperScannerConfigurer 的bean时此配置会被忽略
 * @author hcl
 *
 */
@Configuration
@ConditionalOnMissingBean(MapperScannerConfigurer.class)
@Order(Ordered.HIGHEST_PRECEDENCE)
public class MapperAutoConfiguration {

	/**
	 * 装配mapper处理器
	 * @return
	 */
	@Bean
	@Order(Ordered.HIGHEST_PRECEDENCE)
	@ConditionalOnMissingBean(MapperAutoConfigurationProcessor.class)
	public MapperAutoConfigurationProcessor mapperAutoConfigurationProcessor(){
		Environment environment = ObtainEnvironmentPostProcessor.getEnvironment();
		return new MapperAutoConfigurationProcessor(environment);
	}
	
}
